<!--
 * @Author       : cxh
 * @Date         : 2021-12-20 17:00:00
 * @LastEditTime : 2021-12-21 21:10:53
 * @LastEditors  : cxh
 * @Description  : 
 * @FilePath     : \vue_WorkSpace\day01\basic\bulb.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }

    #bot-Ul {
        width: 400px;
        height: 100px;
        display: flex;
    }

    .item {
        width: 100px;
        height: 100px;
        /* background-color: #0f0; */
        display: flex;
        align-items: center;
        flex-direction: column;
        justify-content: space-between;
    }

    .item>div {
        /* background-color: #ff0; */
        width: 50px;
        height: 50px;
        border-radius: 50px;
        text-align: center;
        line-height: 50px;
    }

    .item>p {
        background-color: #0ff;
    }
</style>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.common.dev.js"></script>

<body>
    <div id="bot-Ul">
        <div class="item" v-for="item in lightlist">
            <!-- <div :style="'background-color:'+(item.lightBool?item.lightColor:'')" v-text=item.value></div> -->

            <div :style="'background-color:'+changeColor(item)" v-text=item.value></div>
            <p @click="handler(item)" v-text=item.title></p>
        </div>
    </div>
</body>
<script>
    new Vue({
        el: "#bot-Ul",
        data: {

            lightlist: [{
                    value: '灯泡1',
                    title: '开关1',
                    lightColor: "blue",
                    lightBool: true
                },
                {
                    value: '灯泡2',
                    title: '开关2',
                    lightColor: "green",
                    lightBool: false
                },
                {
                    value: '灯泡3',
                    title: '开关3',
                    lightColor: "pink",
                    lightBool: false
                },
                {
                    value: '灯泡4',
                    title: '开关4',
                    lightColor: "yellow",
                    lightBool: false
                },
            ]
        },
        methods: {
            handler(item) {
                item.lightBool = !item.lightBool;
            },
            changeColor: function(item){
                return item.lightBool?item.lightColor:''
            }
        },
    })
</script>

</html>